import cv2
import numpy as np

circles_img=cv2.imread(r'misc_pic/circles.jpg')
gray_img=cv2.cvtColor(circles_img,cv2.COLOR_BGR2GRAY)
img=cv2.medianBlur(gray_img,5)
cimg=cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
circles=cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,25,       #25为两个圆心之间的最小距离
                         param1=120,param2=30,minRadius=0,maxRadius=0)
circles=np.uint16(np.around(circles))

for i in circles[0,:]:
    #draw the outer circle
    cv2.circle(circles_img,(i[0],i[1]),i[2], (0,255,0),2)
    #draw the center of the circle
    cv2.circle(circles_img,(i[0],i[1]),2,(0,0,255),3)

cv2.imshow("HoughCircles",circles_img)
cv2.waitKey()
cv2.destroyAllWindows()
